<template>
  <div class="user-info" @click="goToPersonal">
    <img :src="userData.imgUrl" draggable="false" />
    <div class="right">
      <div class="info">
        <span>{{ userData.username }}</span>
        <div class="intro">{{ userData.intro }}</div>
      </div>
      <div
        v-if="userInfo.userId !== userData.userId"
        class="btn"
        style="margin-left: 10%"
      >
        <el-button @click.stop="Follow" :type="isFollow ? '' : 'primary'">{{
          isFollow ? "已关注" : "关注"
        }}</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  props: {
    userData: {
      type: Object,
      default: () => {},
    },
    isFollow: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  methods: {
    // 去个人主页
    goToPersonal() {
      const routePath = this.$router.resolve({
        name: "personal",
        params: {
          personalId: this.userData.userId,
          personalName: this.userData.username,
        },
      }).href;
      // 打开一个新的标签页
      window.open(routePath, "_blank");
    },
    // 关注或取消关注
    Follow() {
      this.$emit("op-follow", this.isFollow);
    },
  },
  computed: {
    ...mapState({
      userInfo: (state) => state.userInfo.userInfo,
    }),
  },
};
</script>

<style lang="less" scoped>
.user-info {
  padding: 15px;
  box-sizing: border-box;
  border-bottom: 1px solid #f0f0f0;
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  &:hover {
    cursor: pointer;
    background-color: #fafafa;
  }
  img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 10px;
    user-select: none;
  }
  .right {
    display: flex;
    align-items: center;
    width: 100%;
    .info {
      width: 80%;
      display: flex;
      flex-direction: column;
      gap: 10px;
      .intro {
        width: 95%;
        color: #c0c0c8;
        font-size: 12px;
        // 溢出显示。。。
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }
    }
  }
}
</style>